<?php
/**
 * Created by PhpStorm.
 * User: william
 * Date: 16-8-30
 * Time: 下午2:15
 */
namespace V1;
class E_Home extends \ResourceClass {
    public $isActive = true;
    public $remark = '企业端首页：获取当前日期前一个月内订单数据（订单数，订单金额，完成率）
		月度销售统计  地域统计 产品统计 客户统计  渠道统计 ';

    public function get(array $req, array $post, &$result)
    {
        if (!isset($req['uid'])) {
            return 'require user id ';
        }
        if (!isset($req['userType'])) {
            return 'require user type';
        }
        if (!isset($req['k']) || !isset($req['t'])) {
            return 'data error';
        }
        if (!isset($req['enterpriseId'])) {
            return 'require enterpriseId';
        }
        if (\Biz\UserHandler::checkAuth($req['userType'],$req['uid'],$req['enterpriseId'],$req['t'],$req['k']) == false) {
            return 'data illegal';
        }
        $reportHandler = new \Biz\ReportHandler();
        try {
            $startTime = array_key_exists('startTime',$req)?$req['startTime']:date('Y-m-d 00:00:00',strtotime('-1 month'));
            $endTime = array_key_exists('endTime',$req)?$req['endTime']:date('Y-m-d 23:59:59');
            $result['home'] 	= $reportHandler->loadThirtyDaysAgoStatistics($req['enterpriseId']);
            $result['monthly']  = $reportHandler->loadMonthlyStatistics($req['enterpriseId']);
            $result['customer']  = $reportHandler->loadCustomerStatistics($req['enterpriseId'],$startTime,$endTime);
            $result['channel']  = $reportHandler->loadChannelStatistics($req['enterpriseId'],$startTime,$endTime);
            $result['product']  = $reportHandler->loadProductStatisticsApi($req['enterpriseId'],$startTime,$endTime);
            $result['territory']  = $reportHandler->loadTerritoryStatistics($req['enterpriseId'],$startTime,$endTime);
            $result['processing_order']  = $reportHandler->loadTerritoryProcessingOrder($req['enterpriseId'],$startTime,$endTime);
        } catch (Exception $e) {
            return $e->getMessage();
        }
        return '';
    }
}